package com.gopay.bis.manager.bank.mtpay;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.annotation.Resource;

import com.gopay.common.constants.bank.MtPayBankConstants;
import com.gopay.common.domain.bank.MtPayBaseMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.businesses.MtPayService;

/**
 * @TBankMtpayManager.java
 * 
 * @author WangHongFei
 */
public class TBankMtPayManager {

	@Resource(name = "tbankMtPayServiceClient")
	private MtPayService tbankMtPayServiceClient;
	@Resource(name = "tbankConfig")
	private Map<String, String> tbankConfig;

    /**
     * 无卡支付
     * 
     * @param MtPayBaseMessage
     * @return MtPayBaseMessage
     * @throws Exception 
     */
    public MtPayBaseMessage pay(MtPayBaseMessage mtPayBaseMessage) throws GopayException {
        Map<String, Comparable> mtbPayHashMap = new ConcurrentHashMap<String, Comparable>();
        mtbPayHashMap.put("mercNo", (String) tbankConfig.get("TBANK.B2C.MerchantNo"));
        mtbPayHashMap.put("msgType", (String) tbankConfig.get("TBANK.MTPAY.MSGTYPE"));
        mtbPayHashMap.put("txnType", (String) tbankConfig.get("TBANK.B2C.TXNTYPE"));
        mtPayBaseMessage.setMtbPayHashMap(mtbPayHashMap);
        mtPayBaseMessage.setCurCode((String) tbankConfig.get("TBANK.CUR.CODE"));
        mtPayBaseMessage.setBankUrl((String) tbankConfig.get("TBANK.MTPAY.BANKURL"));
        mtPayBaseMessage.setMtPayOperType(MtPayBankConstants.MTTPAY_PAY);
        mtPayBaseMessage = (MtPayBaseMessage) this.tbankMtPayServiceClient.query(mtPayBaseMessage);
        return mtPayBaseMessage;
    }

    /**
     * 无卡冲正
     * 
     * @param MtPayBaseMessage
     * @return MtPayBaseMessage
     * @throws Exception 
     */
    public MtPayBaseMessage flush(MtPayBaseMessage mtPayBaseMessage) throws GopayException {
        Map mtbPayHashMap = mtPayBaseMessage.getMtbPayHashMap();
        mtbPayHashMap.put("mercNo", (String) tbankConfig.get("TBANK.B2C.MerchantNo"));
        mtbPayHashMap.put("msgType", (String) tbankConfig.get("TBANK.MTPAY.FLUSH.MSGTYPE"));
        mtbPayHashMap.put("txnType", (String) tbankConfig.get("TBANK.B2C.TXNTYPE"));
        mtPayBaseMessage.setMtbPayHashMap(mtbPayHashMap);
        mtPayBaseMessage.setCurCode((String) tbankConfig.get("TBANK.CUR.CODE"));
        mtPayBaseMessage.setBankUrl((String) tbankConfig.get("TBANK.MTPAY.BANKURL"));
        mtPayBaseMessage.setMtPayOperType(MtPayBankConstants.MTTPAY_FLUSH);
        mtPayBaseMessage = (MtPayBaseMessage) this.tbankMtPayServiceClient.query(mtPayBaseMessage);
        return mtPayBaseMessage;
    }
	
	/**
	 * 获取当前时间
	 * 
	 * @return String
	 */
	private String getCurrDate() {
		Date date = new Date();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String s = sdf.format(date);
		return s;

	}
	
}
